package com.niuke;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 14. 通过软盘拷贝文件
 * 用了和 5. MELON的难题 相同的递归代码，使用不同的判断来得到结果，还有 12. 猜密码 也是这种方法
 * https://blog.csdn.net/qq_34143141/article/details/131466705
 */
public class NiukeMoni16 {

    public static int maxSize;
    public static int fileCount;
    public static int[] fileData = null;
    public static int[] fileSize = null;
    public static int[] tempNum = null;
    public static int[] tempIndex = null;

    public static int resultSize = 0;

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        maxSize = 1474560 / 512;

        fileCount = Integer.parseInt(scanner.nextLine());

        fileData = new int[fileCount];
        fileSize = new int[fileCount];
        tempNum = new int[fileCount];
        tempIndex = new int[fileCount];

        for (int i = 0; i < fileCount; i++) {
            fileData[i] = Integer.parseInt(scanner.nextLine());
            fileSize[i] = (int) Math.ceil(fileData[i] / 512.0);
        }
        System.out.println(Arrays.toString(fileSize));

        dfs(0, 0);

        System.out.println(resultSize);
    }

    public static void dfs(int p, int count) {
        int res = 0;
        int size = 0;
        for (int i = 0; i < count; i++) {
            size += tempNum[i];
            if (size > maxSize) {
                return;
            }
            res += fileData[tempIndex[i]];
            resultSize = Math.max(resultSize, res);
        }

        for (int i = 0; i < fileCount; i++) {
            boolean flag = false;
            for (int j = 0; j < count; j++) {
                if (tempIndex[j] == i) {
                    flag = true;
                    break;
                }
            }

            if (!flag) {
                tempNum[count] = fileSize[i];
                tempIndex[count] = i;
                dfs(p + 1, count + 1);
            }
        }

    }

}
